package com;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pojo.EasyExcelUtils;
import com.pojo.Username;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: fanyouzhao
 * @date: 13:36 2021/6/29
 */
public class Login {
    public static String login(String username) throws IOException, ParseException {
        String url = "https://sczyz.org.cn/apiv1/zysc/admin/login";
        // String username = "成都文理学院";
        String password = "123456";
        String param =  "{\n" +
                "    \"username\": \""+username+"\",\n" +
                "    \"password\": \""+password+"\"\n" +
                "}";
        JSONObject jsonObject = JSONObject.parseObject(param);
        String back = HttpRequestUtils.send(url, jsonObject, "utf-8");
        // System.out.println("send = " + back);
        JSONObject backLogin = JSONObject.parseObject(back);
        String code = backLogin.getString("code");
        // System.out.println("code = " + code);
        // ArrayList<Username> usernames = new ArrayList<>();
        if ("200".equals(code)){
            System.out.println(username);
            // usernames.add(new Username(username));
        }
        return jsonObject.getString("code");
    }
}
